#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <math.h>

#define MEMORY_SIZE 20

using namespace std;

void printError()
{
	cout << "ERROR: Connection failed" << '\n';
}

int main()
{
    int shmid;
    char *sharedMemory;
    
    shmid = shmget(2404, MEMORY_SIZE, 0666);
    if (shmid >= 0) 
    {
        sharedMemory = (char*)shmat(shmid, 0, 0);
        if (sharedMemory==(char *)-1) 
		{
			printError();
		}
        else 
        {
			cout << "Type \"rdy\" and hit enter when prgram 1 is ready.\n";
			int a;
			cin >> a;
			
			
			cout << "Calculating...\n";

            float number;
            number = sharedMemory[0];
	    number *= number;
            sharedMemory[0] = number;
            shmdt(sharedMemory);

			cout << "Done!\n";
        }
    } 
    else 
	{
		printError();
	}
    
    return 0;
}
